package main

import (
	"fmt"
	"image"
	"image/color"
	"image/draw"
	"image/png"
	"os"

	"github.com/nfnt/resize"
	"golang.org/x/image/bmp"
)

var (
	width = 280
	bg    = image.White
	black = color.Black
)

type signOrder struct {
	PrintContent []struct {
		Content     string `json:"content,omitempty"`
		ContentType string `json:"content-type"`
		Position    string `json:"position"`
		Height      int    `json:"height,omitempty"`
		Size        string `json:"size,omitempty"`
	} `json:"print-content"`
	PrintFile []struct {
		FileName string `json:"file-name"`
	} `json:"print-file"`
	DefualtParams struct {
		SpaceHeight int `json:"space-height"`
		PaperWidth  int `json:"paper-width"`
	} `json:"defualt-params"`
}

func main() {
	// f, _ := os.Open("201903113597547.txt")
	// b := bufio.NewScanner(f)
	// // b, _ := ioutil.ReadAll(f)
	// // fmt.Println(*(*string)(unsafe.Pointer(&b)))

	// s := new(signOrder)
	// for b.Scan() {
	// 	_ = json.Unmarshal(b.Bytes(), s)
	// }

	// fmt.Println(s)
	newPaper()
}

func newPaper() {
	jpg := image.NewRGBA(image.Rect(0, 0, width, 500))
	draw.Draw(jpg, jpg.Bounds(), bg, image.ZP, draw.Src)

	header, _ := os.Open("style/logo.bmp")
	dheader, e := bmp.Decode(header)
	if e != nil {
		fmt.Println(e)
		return
	}
	hY := dheader.Bounds().Min.Y * (dheader.Bounds().Max.X / width)
	dheader = resize.Resize(uint(width-20), uint(hY), dheader, resize.Lanczos3)
	fmt.Println(dheader.Bounds().Max)

	draw.Draw(jpg, image.Rect(10, 0, dheader.Bounds().Size().X+20, dheader.Bounds().Size().Y), dheader, dheader.Bounds().Min, draw.Src)

	so, _ := os.Create("signOrder.jpg")
	png.Encode(so, jpg)
}
